package org.example;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HadoopConnectUtil {


    private static FileSystem fileSystem;

    public static FileSystem getFileSystem() {
        System.setProperty("hadoop.home.dir", "/opt/hadoop-3.3.6");
        try {
            // 连接
            URI uri = new URI("hdfs://hadoop102:8020");
            Configuration configuration = new Configuration();

            // 获取客户端对象
            fileSystem = FileSystem.get(uri, configuration);
            return fileSystem;
        } catch (URISyntaxException | IOException e) {
            throw new RuntimeException(e);
        }
    }
}

